@isTest(SeeAllData=true)
private class Cbl_WorkOrderProductToAssertTest {
    static testMethod void testMethod1() {

    	Id ldcProfile = [Select Id From Profile Where Name ='销售部直销销售员' ].Id;

         User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         CompanyName= 'Y-MKSY',
                         FederationIdentifier = '123451',
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123451',
                         ManagerId =UserInfo.getUserId(),
                         Province__c = '四川省',
                         Username = 'Matldc1@test.com.maike',
                         ResponseCode__c = 'TTTT' );
         insert u1;
          //产品结构
        ProductStructure__c ps1=new ProductStructure__c();
        ps1.Name='仪器';
        ps1.Classify1__c='生化';
        ps1.Classify2__c='生化-设备';
        ps1.Classify3__c='仪器';
        insert ps1;
        Brand__c brand = new Brand__c(
        	BrandShortName__c = '四川迈克'
        );
        insert brand;
          //产品
        Product__c p1=TestUtils.createProduct();
        p1.Name='仪器';
        p1.Category0__c = '仪器';
        p1.Model__c='Model1228';
        p1.ProductStructure__c=ps1.Id;
        p1.CRMBrand__c = brand.Id;
        p1.RecordTypeId =  Utils.getRecordTypeIdByDevNameAndObjName('NCProduct','Product__c');
        insert p1;
         Province__c province  = new Province__c();
       province.Name = '四川';

       insert province ;

         City__c city = new City__c();
       city.Province__c = province.Id;
       insert city;

         Account acc=new Account();
        acc.Name='Test1229J';
        acc.Level__c = '一级医院';
        acc.Province__c = province.Id;
        acc.City__c = city.Id;
        insert acc;
        Dealer__c d = new Dealer__c(
        	Only__c='Dealer__c'
        );
        insert d;


        InstallationApply__c ins = new InstallationApply__c();
        ins.InstallationType__c='新装机';
        //必填字段 chatter 通知工作流引用到的字段都为必填字段
        ins.Instrument__c = p1.Id;
        ins.NEWDealer__c = d.Id;
        ins.Hospital__c = acc.Id;
        ins.InstallEstiDate__c = Date.newInstance(2017, 12, 1);
        ins.InstallsNumber__c = 1;
        ins.EffectiveTime__c = System.now();
        insert ins;

        Case cas=new Case();
        cas.AccountId=acc.Id;
        cas.InstallationApply__c = ins.Id;
        insert cas;


          Case cas1=new Case();
        cas1.AccountId=acc.Id;
        cas1.InstallationApply__c = ins.Id;
        insert cas1;



        WorkOrder__c wo=new WorkOrder__c();
        wo.Case__c=cas.Id;
        wo.Account__c=acc.Id;
        wo.Status__c='处理中';
        wo.ManufactureInfo__c=p1.Id;
        wo.IMEINumber__c = '1245';
        wo.recordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('InstallationOrder','WorkOrder__c');
        wo.WhetherToMakeASingle__c = '否';
        insert wo;

          system.Test.startTest();

        wo.Status__c = '完成';
        update wo ;


      

        WorkOrder__c wo1=new WorkOrder__c();
        wo1.Case__c=cas1.Id;
        wo1.Account__c=acc.Id;
        wo1.Status__c='完成';
        wo1.IMEINumber__c = 'x0003';
        wo1.ManufactureInfo__c=p1.Id;
        wo1.recordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NonAgentInstallationOrder','WorkOrder__c');
        insert wo1;

       

         wo1.Status__c = '完成';
        update wo1 ;
        
/*
        Equipment__c eq=[select Id,type__c from Equipment__c where Product__c=:p1.Id and IMEINumber__c='1245' limit 1 ];
        eq.type__c ='退机';
        update  eq;





        wo.Status__c = '处理中';
        update wo;

        
        ins.ReturnedMachine__c = eq.Id;
        update ins;
        wo.Status__c = '完成';
        try {
            update wo;
        }
        catch (Exception e) {
            
        }
        */
        
        
       



       
    }

     static testMethod void testMethod2() {

        Id ldcProfile = [Select Id From Profile Where Name ='销售部直销销售员' ].Id;

         User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         CompanyName= 'Y-MKSY',
                         FederationIdentifier = '123451',
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                          ManagerId =UserInfo.getUserId(),
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123451',
                         Province__c = '四川省',
                         Username = 'Matldc1@test.com.maike',
                         ResponseCode__c = 'TTTT' );
         insert u1;

         Province__c province  = new Province__c();
       province.Name = '四川';

       insert province ;

         City__c city = new City__c();
       city.Province__c = province.Id;
       insert city;

        Account acc=new Account();
        acc.Name='Test1229J';
        acc.Level__c = '一级医院';
        acc.Province__c = province.Id;
        acc.City__c = city.Id;
        insert acc;

         Case cas=new Case();
        cas.AccountId=acc.Id;
       // cas.InstallationApply__c = ins.Id;
        insert cas;

        //产品结构
        ProductStructure__c ps1=new ProductStructure__c();
        ps1.Name='仪器';
        ps1.Classify1__c='生化';
        ps1.Classify2__c='生化-设备';
        ps1.Classify3__c='仪器';
        insert ps1;

         Product__c p2 = TestUtils.createProduct();
            p2.Category0__c = '仪器';
            p2.PriceCompany__c = 'MKSY';
            p2.NCCode__c = '000002';
            p2.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
            insert p2;

        Equipment__c eq = new Equipment__c();
            eq.Account__c = acc.Id;
            eq.IMEINumber__c = 'xxx321';
            eq.Product__c = p2.Id ; 
            eq.FromFlow__c = 1;
            insert eq;


             ////工单项目触发器
       WorkOrder__c wo3=new WorkOrder__c();
        wo3.Case__c=cas.Id;
        wo3.Account__c=acc.Id;
        wo3.Status__c='处理中';
        wo3.ServiceManufacture__c= eq.Id ;
        //wo3.Signed_UsedDepartmen__c = true;
        wo3.recordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Reagents','WorkOrder__c');
       insert wo3;

        System.Test.startTest();

       ProductProject__c  pp = new ProductProject__c();
       pp.ProductStructure__c = ps1.Id ; 
       pp.ShortItems__c = '11344';
       insert pp;
        WorkOrderItems__c woi = new WorkOrderItems__c();
        woi.WorkOrder__c = wo3.Id;
        woi.Items__c = pp.Id ;

        
        insert woi ;

        WorkOrderTeam__c wt = new WorkOrderTeam__c();
        wt.User__c = u1.Id;
        wt.WorkOrder__c = wo3.Id;
        wt.Name = 'xxxx';

        insert wt;

        wo3.Status__c = '完成';
        update wo3;
     }


}